package main

import (
	"fmt"
	"strconv"
	"strings"
)

const(
	Cyan = 0
	Magenta = 1
	Yellow = 2
	Blue = iota
	Red = iota//iota的值将比前一个数值递增
)

const(
	Apple = iota
	Orange = iota
	Tangerine = iota
	Watermelon = iota
	Cherry = iota//iota的值将比前一个数值递增
)

type BitFlag int//自定义BitFlag类型，此类型实际为int类型
const(
	One BitFlag = 1 << iota//表示设置1  小数点向左移动0位  1 << 0 结果为1
	Two			//隐式设置为 Two BitFlag = 1 << 1 结果为2
	Three			//隐式设置为 Two BitFlag = 1 << 2 结果为4
	Four			//隐式设置为 Two BitFlag = 1 << 3 结果为8
	Five			//隐式设置为 Two BitFlag = 1 << 4 结果为16
	Six			//隐式设置为 Two BitFlag = 1 << 5 结果为32
)
//相当于定义了BitFlag的String方法，所有BitFlag类型都可以调用此方法
func (flag BitFlag) String() string{
	var flags [] string
	if flag & One == One{
		flags = append(flags,"One")
	}
	if flag & Two == Two{
		flags = append(flags,"Two")
	}
	if flag & Three == Three{
		flags = append(flags,"Three")
	}
	if flag & Four == Four{
		flags = append(flags,"Four")
	}
	if flag & Five == Five{
		flags = append(flags,"Five")
	}
	if flag & Six == Six{
		flags = append(flags,"Six")
	}
	if len(flags) > 0{
		return fmt.Sprintf("%d(%s)",int(flag),strings.Join(flags,"|"))
	}
	return "0()"
}

func main(){
	fmt.Println("Magenta is " + strconv.Itoa(Magenta))
	fmt.Println("Blue is " + strconv.Itoa(Blue))
	fmt.Println("Red is " + strconv.Itoa(Red))
	fmt.Println("-----------------------------------------")
	fmt.Println("Apple is " + strconv.Itoa(Apple))
	fmt.Println("Tangerine is " + strconv.Itoa(Tangerine))
	fmt.Println("Cherry is " + strconv.Itoa(Cherry))
	fmt.Println("-----------------------------------------")
	fmt.Println("One is " ,One)
	fmt.Println("Two is " ,Two)
	fmt.Println("Three is " ,Three)
	fmt.Println("Four is " ,Four)
	fmt.Println("Five is " ,Five)
	fmt.Println("Six is " ,Six)
	fmt.Println("-----------------------------------------")
	fmt.Println("Stirng --- ",Two.String())
}
